﻿<template>
  <div></div>
</template>

<script>
import axios from 'axios'
// ws事件相关的操作部分
import WSTrigger from '@/components/WebSocketComponents/WebSocketConsole.vue'
import { commonUse_defaultMethod, commonUse_changeInherentEventParams, commonUse_changeOutputParams } from '@/components/commonUse.js'
export default {
  components: { WSTrigger },
  data () {
    return {
      loading: false,
      loadingText: '页面加载中...',
      // 获取的设定的页面信息
      pageFormInfo: '',
      // 页面表单的基本信息
      models: {},
      rules: {},
      // 页面中所有的单个元素
      allSingleElement: [],
      // 当前事件的信息
      currentEventInfo: {
        no: '',
        name: '',
        category: '',
        request_parameters: '',
        response_data: ''
      },
      // 当为展示流程信息时
      currentShow: 'basicInfo',
      // 页面数据改变时,通知子组件获取数据
      changeModels: false,
      pageInit: false, // 页面有初始化事件时,在初始化事件完成之后,通知子组件重新渲染
      // 判断事件的类型，RequestUrl是以~开头的是本地事件，否则是http事件
      isLocalEvent: true,
      // 当为流程界面时，判断界面流程相关的按钮的状态
      workflowBtnStatus: {
        Delete: [],
        Save_add: [],
        Save_edit: [],
        Submit: [],
        Pass: [],
        Reject: [],
        SelectReject: [],
        Stop: [],
        Apply: [],
        SubmitPending: [],
        ActivePending: []
      },
      // 保存事件后得到的primaryKey的主键/status等参数
      workFlowParams: {
        primaryKey: '',
        status: ''
      },
      // 事件的请求和响应的数据----api的键/页面展示的键/值/事件编号
      // inputArray----apiKey/pageKey/eventNo
      // outputArray----apiKey/pageKey/value/eventNo
      pagePrimaryObj: {
        inputArray: [],
        outputArray: []
      },
      // 当前执行事件的集合
      currentEventsArray: [],
      // 对于特殊的需要选人的节点
      NextUserList: null,
      currentClickType: '',
      showUserDialog: false,
      // 需要调用ws的弹窗相关的信息
      wsDialogInfo: {
        visible: false,
        title: '',
        wsApiRouter: ''
      }
    }
  },
  methods: {
    // 对象数组排序
    orderByObjAttr (key) {
      return function (val1, val2) {
        return val1[key] - val2[key]
      }
    },
    // 获取表单的基本信息
    getFormInfo (genList) {
      for (let i = 0; i < genList.length; i++) {
        if (genList[i].type === 'grid') {
          genList[i].columns.forEach(item => {
            this.getFormInfo(item.list)
          })
        } else if (genList[i].type === 'tabs') {
          for (let t = 0; t < genList[i].tabList.length; t++) {
            this.getFormInfo(genList[i].tabList[t].list)
          }
        } else {
          // 控制表单是否可以输入-----在已办列表中点击查看详细
          if (this.dialogType === 'showDetail' && genList[i].options && Object.keys(genList[i].options).indexOf('disabled') >= 0) {
            genList[i].options.disabled = true
          }
          // 获取页面中所有的单个元素---表单元素
          this.allSingleElement.push(genList[i])
          // models中不添加类型为table/button/pagination的元素
          if (genList[i].type !== 'table' && genList[i].type !== 'button' && genList[i].type !== 'pagination') {
            if (genList[i].type === 'editableTable') {
              this.models[genList[i].model] = genList[i].tableData
            } else if (genList[i].type === 'echarts' || genList[i].type === 'GIS_Draw_Line') {
              this.models[genList[i].model] = null
            } else if (genList[i].type === 'Switch' || genList[i].type === 'switch') {
              this.models[genList[i].model] = genList[i].options.defaultValue ? genList[i].options.defaultValue : false
            } else if (genList[i].type === 'CheckBox') {
              this.models[genList[i].model] = genList[i].options.defaultValue ? genList[i].options.defaultValue : []
            } else if (genList[i].type === 'StarRate' || genList[i].type === 'SlideInput') {
              this.models[genList[i].model] = genList[i].options.defaultValue ? genList[i].options.defaultValue : 0
            } else {
              let defaultValue = genList[i].options.defaultValue
              let fixedValue = {
                formKey: this.dynamicUid,
                limit: 10,
                page: 1
              }
              let rowData = (this.clickRow && !this.$isEmptyObject(this.clickRow)) ? JSON.parse(JSON.stringify(this.clickRow)) : null
              let pPageRowData = (this.pPageRow && !this.$isEmptyObject(this.pPageRow)) ? JSON.parse(JSON.stringify(this.pPageRow)) : null
              let getDefaultValue = defaultValue ? commonUse_defaultMethod(defaultValue, null, fixedValue, rowData, pPageRowData) : null
              this.models[genList[i].model] = getDefaultValue
            }
          }
          // 获取表单验证的规则
          if (this.rules[genList[i].model]) {
            this.rules[genList[i].model] = [...this.rules[genList[i].model], ...genList[i].rules.map(item => {
              if (item.pattern) {
                return {...item, pattern: item.pattern}
              } else {
                return {...item}
              }
            })]
          } else {
            this.rules[genList[i].model] = [...genList[i].rules.map(item => {
              if (item.pattern) {
                return {...item, pattern: new RegExp(item.pattern)}
              } else {
                return {...item}
              }
            })]
          }
        }
      }
      // 编辑时，需要初始化弹窗
      if ((this.dialogType === 'handle' || this.dialogType === 'editTable' || this.dialogType === 'selfDefineDialogTable' || this.dialogType === 'showDetail') && !this.$isEmptyObject(this.models)) {
        let rowData = null
        if (this.pPageRow && !this.$isEmptyObject(this.pPageRow)) {
          rowData = JSON.parse(JSON.stringify(this.pPageRow))
        }
        if (this.clickRow && !this.$isEmptyObject(this.clickRow)) {
          rowData = rowData ? Object.assign(rowData, JSON.parse(JSON.stringify(this.clickRow))) : JSON.parse(JSON.stringify(this.clickRow))
        }
        for (let modelKey in this.models) {
          if (rowData && !this.$isEmptyObject(rowData)) {
            for (let rowKey in rowData) {
              if (modelKey === rowKey) {
                this.models[modelKey] = rowData[rowKey]
              } else {
                this.$set(this.models, rowKey, rowData[rowKey])
              }
            }
          }
        }
      }
    },
    // ---------------------------------------执行的是自定义事件---开始
    // 根据事件编号获取该事件的key值(事件编号、执行的顺序)
    getEventKeyByEventNo (targetEventNo, evalIndex) {
      let allDictionary = null
      if (this.currentEventsArray[evalIndex - 1].eventsNo && this.currentEventsArray[evalIndex - 1].eventsNo === targetEventNo) {
        allDictionary = this.currentEventsArray[evalIndex - 1]
      }
      // 每次将this.pagePrimaryObj.inputArray清空
      this.pagePrimaryObj.inputArray = []
      if (allDictionary && !this.$isEmptyObject(allDictionary) && allDictionary.inputDic) {
        // 输入的参数格式为：api中的键名 = 页面展示的键名
        for (let i = 0; i < allDictionary.inputDic.length; i++) {
          if (allDictionary.inputDic[i].inputKey.indexOf('=') !== -1) {
            let dicInputArray = allDictionary.inputDic[i].inputKey.split('=')
            let obj = {
              apiKey: dicInputArray[0],
              pageKey: dicInputArray[1],
              eventNo: targetEventNo
            }
            this.pagePrimaryObj.inputArray.push(obj)
          }
        }
      }
      // 获取输出的参数
      if (allDictionary && !this.$isEmptyObject(allDictionary) && allDictionary.outputDic) {
        // 输出的参数格式为： 页面展示的键名 = api中的键名
        for (let i = 0; i < allDictionary.outputDic.length; i++) {
          if (allDictionary.outputDic[i].outputKey.indexOf('=') !== -1) {
            let dicOutputArray = allDictionary.outputDic[i].outputKey.split('=')
            let hadPushed = false
            // 判断该事件的输出参数是否已经加入过一次
            if (this.pagePrimaryObj.outputArray.length) {
              for (let i = 0; i < this.pagePrimaryObj.outputArray.length; i++) {
                if (targetEventNo === this.pagePrimaryObj.outputArray[i].eventNo && this.pagePrimaryObj.outputArray[i].apiKey === dicOutputArray[1] && this.pagePrimaryObj.outputArray[i].pageKey === dicOutputArray[0]) {
                  hadPushed = true
                }
              }
            }
            if (!hadPushed) {
              let obj = {
                apiKey: dicOutputArray[1],
                pageKey: dicOutputArray[0],
                value: null,
                eventNo: targetEventNo
              }
              this.pagePrimaryObj.outputArray.push(obj)
            }
          }
        }
      }
    },
    // 根据事件编号获取事件详细---事件编号、是否是初始化事件(事件类型)、事件执行的顺序、元数据表的uid、流程事件的类别（delete/save/submit/pass/reject/stop
    getEventsInfoByEventNo (eventItemNo, eventType, evalIndex, evalMetauid, workflowEventItem) {
      if (!eventItemNo) {
        this.$message({
          message: '该操作没有指定事件，请在元数据页面管理中进行设置',
          type: 'error'
        })
        this.loading = false
        return
      }
      // 获取该事件的key值
      this.getEventKeyByEventNo(eventItemNo, evalIndex)
      // 获取事件的详细
      this.$get('/events4dform/' + eventItemNo).then(data => {
        let dataInfo = data.data.result
        if (dataInfo.code === 'failed') {
          this.loading = false
          this.$message({
            message: dataInfo.msg,
            type: 'error'
          })
        }
        if (dataInfo.code === 'success') {
          this.currentEventInfo = {
            no: dataInfo.data.no,
            name: dataInfo.data.name,
            category: dataInfo.data.category,
            request_parameters: dataInfo.data.request_parameters,
            response_data: dataInfo.data.response_data
          }
          // 需要先判断事件是否为ws事件
          if (this.currentEventInfo.request_parameters) {
            let parametersObj = JSON.parse(this.currentEventInfo.request_parameters)
            if (parametersObj.RequestUrl.indexOf('~') === 0 && parametersObj.RequestMethod === 'WS') {
              // 获取触发事件的parameters
              let evalParamters = {}
              // 将this.clickRow和submitData合并
              let submitData = JSON.parse(JSON.stringify(this.models))
              if (this.pPageRow && !this.$isEmptyObject(this.pPageRow)) {
                submitData = Object.assign(JSON.parse(JSON.stringify(this.pPageRow)), submitData)
              }
              if (this.clickRow && !this.$isEmptyObject(this.clickRow)) {
                submitData = Object.assign(JSON.parse(JSON.stringify(this.clickRow)), submitData)
              }
              if (this.pagePrimaryObj.inputArray.length) {
                this.pagePrimaryObj.inputArray.forEach(item => {
                  // 找到该事件对应的参数
                  if (item.eventNo === eventItemNo) {
                    // 判断apiKey是否是 Query.key的结构（Query表示的是字段名，key表示的是该对象中的一个属性）
                    if (item.apiKey.indexOf('.') !== -1) {
                      let apiObjString = item.apiKey.split('.')
                      // 需要先判断该对象是否已经存在于evalParamters中
                      if (Object.keys(evalParamters).indexOf(apiObjString[0]) === -1) {
                        evalParamters[apiObjString[0]] = {}
                      }
                      evalParamters[apiObjString[0]][apiObjString[1]] = this.getInputParamsMethods(item.pageKey, submitData)
                    } else {
                      evalParamters[item.apiKey] = this.getInputParamsMethods(item.pageKey, submitData)
                    }
                  }
                })
              }
              // 修改后的参数--如果有词典表，则获取词典表中的数据值，否者就直接为models中的值
              let parameters = this.$isEmptyObject(evalParamters) ? submitData : evalParamters
              let wsQueryStringArray = []
              if (parametersObj.RequestQueryString && !this.$isEmptyObject(parametersObj.RequestQueryString) && parameters && !this.$isEmptyObject(parameters)) {
                for (let searchKey in parametersObj.RequestQueryString) {
                  for (let parametersKey in parameters) {
                    if (searchKey === parametersKey) {
                      let queryArrayString = searchKey + '=' + parameters[parametersKey]
                      wsQueryStringArray.push(queryArrayString)
                    }
                  }
                }
              }
              // 获取ws请求的url地址
              let wsApiRouter = parametersObj.RequestUrl.slice(1)
              if (wsQueryStringArray.length) {
                wsApiRouter = wsApiRouter + '?' + wsQueryStringArray.join('&')
              }
              // 触发ws相关的事件
              this.$set(this.wsDialogInfo, 'visible', true)
              this.$set(this.wsDialogInfo, 'title', dataInfo.data.name)
              this.$set(this.wsDialogInfo, 'wsApiRouter', wsApiRouter)
              this.loading = false
            } else {
              if (parametersObj.RequestUrl.indexOf('~') === 0) {
                this.isLocalEvent = true
              } else {
                this.isLocalEvent = false
              }
              // 触发事件前修改事件参数
              this.changeEventsInfoBeforeSubmit(eventItemNo, eventType, evalIndex, evalMetauid, workflowEventItem)
            }
          } else {
            this.$message({
              message: '没有获取到触发事件的相关信息',
              type: 'error'
            })
            this.loading = false
          }
        }
      }).catch(error => {
        this.loading = false
        this.$message({
          message: error,
          type: 'warning'
        })
      })
    },
    // -------------------修改输出和输入方法的--开始
    // 修改输入参数的公共方法
    getInputParamsMethods (pageKey, submitData) {
      let inputKeyValue = ''
      let fixedValue = {
        formKey: this.dynamicUid,
        primaryKey: this.workFlowParams.primaryKey,
        status: this.workFlowParams.status,
        limit: 10,
        page: 1
      }
      let rowData = (this.clickRow && !this.$isEmptyObject(this.clickRow)) ? JSON.parse(JSON.stringify(this.clickRow)) : null
      let pPageRowData = (this.pPageRow && !this.$isEmptyObject(this.pPageRow)) ? JSON.parse(JSON.stringify(this.pPageRow)) : null
      inputKeyValue = pageKey ? commonUse_defaultMethod(pageKey, submitData, fixedValue, rowData, pPageRowData) : null
      return inputKeyValue
    },
    // 修改触发事件后，输出参数对应的词典表信息
    changeOutputParames (data, eventItemNo) {
      let fixedValue = {
        formKey: this.dynamicUid,
        primaryKey: this.workFlowParams.primaryKey,
        status: this.workFlowParams.status,
        limit: 10,
        page: 1
      }
      let changeParamsArray = commonUse_changeOutputParams(data, eventItemNo, this.pagePrimaryObj.outputArray, this.models, fixedValue)
      if (changeParamsArray && changeParamsArray.length) {
        changeParamsArray.forEach(item => {
          this.$set(this.pagePrimaryObj.outputArray[item.index], 'value', item.pageValue)
          if (item.pageKey === '$_PrimaryKey') {
            this.workFlowParams.primaryKey = item.pageValue
          } else {
            this.$set(this.models, item.pageKey, item.pageValue)
          }
        })
      }
    },
    // -------------------修改输出和输入方法--结束
    // 获取页面配置时定义的所有的参数this.pagePrimaryObj.inputArray中的键值对应的参数
    changeEventsInfoBeforeSubmit (eventItemNo, eventType, evalIndex, evalMetauid, workflowEventItem) {
      // 将this.clickRow和submitData合并
      let submitData = JSON.parse(JSON.stringify(this.models))
      if (this.pPageRow && !this.$isEmptyObject(this.pPageRow)) {
        submitData = Object.assign(JSON.parse(JSON.stringify(this.pPageRow)), submitData)
      }
      if (this.clickRow && !this.$isEmptyObject(this.clickRow)) {
        submitData = Object.assign(JSON.parse(JSON.stringify(this.clickRow)), submitData)
      }
      // 获取触发事件的parameters
      let evalParamters = {}
      if (this.pagePrimaryObj.inputArray.length) {
        this.pagePrimaryObj.inputArray.forEach(item => {
          // 找到该事件对应的参数
          if (item.eventNo === eventItemNo) {
            // 判断apiKey是否是 Query.key的结构（Query表示的是字段名，key表示的是该对象中的一个属性）
            if (item.apiKey.indexOf('.') !== -1) {
              let apiObjString = item.apiKey.split('.')
              // 需要先判断该对象是否已经存在于evalParamters中
              if (Object.keys(evalParamters).indexOf(apiObjString[0]) === -1) {
                evalParamters[apiObjString[0]] = {}
              }
              evalParamters[apiObjString[0]][apiObjString[1]] = this.getInputParamsMethods(item.pageKey, submitData)
            } else {
              evalParamters[item.apiKey] = this.getInputParamsMethods(item.pageKey, submitData)
            }
          }
        })
      }
      let toEvalMethodJsonString = this.$isEmptyObject(evalParamters) ? '' : evalParamters
      this.triggerRowEventMethod(submitData, eventItemNo, eventType, evalIndex, workflowEventItem, toEvalMethodJsonString, evalMetauid)
    },
    // 触发事件的方法
    triggerRowEventMethod (submitData, eventItemNo, eventType, evalIndex, workflowEventItem, parameters, evalMetauid) {
      if (this.isLocalEvent) {
        // 如果是本地事件的触发方式
        this.$post('/events4dform/' + eventItemNo + '/eval', {
          this_data: btoa(encodeURIComponent(JSON.stringify(submitData))),
          parameters: parameters
        }).then(data => {
          let dataInfo = data.data.result
          this.afterEval(dataInfo, eventType, eventItemNo, evalIndex, evalMetauid, workflowEventItem)
        }).catch(error => {
          this.loading = false
          this.$message({
            message: error,
            type: 'error'
          })
        })
      } else {
        // http事件的出发方式
        if (this.currentEventInfo.request_parameters) {
          let requestObj = JSON.parse(this.currentEventInfo.request_parameters)
          if (!this.$isEmptyObject(requestObj) && requestObj.RequestUrl && requestObj.RequestMethod) {
            let axiosUrl = requestObj.RequestUrl
            // 改变path
            if (requestObj.RequestPath && !this.$isEmptyObject(requestObj.RequestPath)) {
              // 获取请求的url中的path---将url中的变量的改为获取到的值
              for (let pathKey in requestObj.RequestPath) {
                for (let modelKey in submitData) {
                  if (pathKey === modelKey) {
                    axiosUrl = axiosUrl.replace('{' + pathKey + '}', submitData[pathKey])
                  }
                }
              }
            }
            // 修改query的值
            let axiosQuery = {}
            if (requestObj.RequestQueryString && !this.$isEmptyObject(requestObj.RequestQueryString) && parameters) {
              for (let searchKey in requestObj.RequestQueryString) {
                for (let parametersKey in parameters) {
                  if (searchKey === parametersKey) {
                    axiosQuery[searchKey] = parameters[parametersKey]
                  }
                }
              }
            }
            // 修改postData的值
            let axiosPostData = {}
            if (requestObj.RequestPostData && !this.$isEmptyObject(requestObj.RequestPostData) && parameters) {
              for (let postKey in requestObj.RequestPostData) {
                for (let parametersKey in parameters) {
                  if (postKey === parametersKey) {
                    axiosPostData[postKey] = parameters[parametersKey]
                  }
                }
              }
            }
            axios({
              url: axiosUrl,
              method: requestObj.RequestMethod,
              // headers: requestObj.RequestHeader,
              data: axiosPostData,
              params: axiosQuery
            }).then(data => {
              let dataInfo = data.data.result
              this.afterEval(dataInfo, eventType, eventItemNo, evalIndex, evalMetauid, workflowEventItem)
            }).catch(error => {
              this.loading = false
              this.$message({
                message: error,
                type: 'error'
              })
            })
          }
        }
      }
    },
    // ---------------------------------------执行的是自定义事件---结束
    // 提交表单时
    getFormData (childItem) {
      if (this.$refs['formMenuLayout'].validateFormMethod() && childItem && childItem.eventsArray && childItem.eventsArray.length) {
        this.loading = true
        if (!this.pageFormInfo.pageConfig.refMainMetaTableUid) {
          this.$message({
            message: '该页面中还没有指定元数据表，请在元数据页面管理中进行设置',
            type: 'warning'
          })
          this.loading = false
          return
        }
        this.currentEventsArray = JSON.parse(JSON.stringify(childItem.eventsArray))
        // 需要判断是不是固定的事件
        if (this.currentEventsArray[0].actionIndex === 0) {
          // 提交新增事件时
          if (this.currentEventsArray[0].eventsType === 'submitDialogForm_add' || this.currentEventsArray[0].eventsType === 'submitForm_add') {
            this.evalSubmitAddFormDataMethod(this.currentEventsArray[0].eventsType, 1, this.pageFormInfo.pageConfig.refMainMetaTableUid, null)
          } else if (this.currentEventsArray[0].eventsType === 'submitDialogForm_edit' || this.currentEventsArray[0].eventsType === 'submitForm_edit') {
            // 提交编辑事件时
            this.evalSubmitEditFormDataMethod(this.currentEventsArray[0].eventsType, 1, this.pageFormInfo.pageConfig.refMainMetaTableUid, null)
          } else if (this.currentEventsArray[0].eventsType === 'extend_save') {
            // 保存事件时
            this.evalExtendEventOfSaveMethod('extend_save', 1, this.pageFormInfo.pageConfig.refMainMetaTableUid, null)
          } else if (this.currentEventsArray[0].eventsType === 'extend_submit') {
            // 提交事件时
            this.evalExtendEventOfSubmitMethod('extend_submit', 1, this.pageFormInfo.pageConfig.refMainMetaTableUid, null)
          } else if (this.currentEventsArray[0].eventsType === 'extend_pass') {
            // 通过事件时
            this.evalExtendEventOfPassMethod('extend_pass', 1, this.pageFormInfo.pageConfig.refMainMetaTableUid, null)
          } else if (this.currentEventsArray[0].eventsType === 'extend_reject') {
            // 驳回事件时
            this.evalExtendEventOfRejectMethod('extend_reject', 1, this.pageFormInfo.pageConfig.refMainMetaTableUid, null)
          } else if (this.currentEventsArray[0].eventsType === 'extend_finish') {
            // 完成事件时
            this.evalExtendEventOfFinishMethod('extend_finish', 1, this.pageFormInfo.pageConfig.refMainMetaTableUid, null)
          } else if (this.currentEventsArray[0].eventsType === 'extend_stop') {
            // 终止事件时
            this.evalExtendEventOfStopMethod('extend_stop', 1, this.pageFormInfo.pageConfig.refMainMetaTableUid, null)
          }
        } else {
          this.getEventsInfoByEventNo(this.currentEventsArray[0].eventsNo, this.currentEventsArray[0].eventsType, 1, this.pageFormInfo.pageConfig.refMainMetaTableUid, null)
        }
      }
    },
    // 按钮执行事件(执行完成后关闭弹窗)
    tirggerSelfdefineEventClose (childItem) {
      this.currentEventsArray = JSON.parse(JSON.stringify(childItem.eventsArray))
      this.getEventsInfoByEventNo(this.currentEventsArray[0].eventsNo, this.currentEventsArray[0].eventsType, 1, this.pageFormInfo.pageConfig.refMainMetaTableUid, null)
    },
    // ---执行固定事件时需要用到的公用方法
    // 1.获取需要提交的数据资料
    getPostFormData () {
      // 需要返回的数据
      let formDataObj = {}
      // 主表的uid
      let mainMetaTableUid = this.pageFormInfo.pageConfig.refMainMetaTableUid
      if (this.allSingleElement.length) {
        this.allSingleElement.forEach(item => {
          if (item.type !== 'button' && item.type !== 'table' && item.type !== 'pagination' && item.type !== 'grid' && item.type !== 'tabs' && item.metauid) {
            if (Object.keys(this.models).indexOf(item.model) !== -1) {
              // 找到model中对应的元素
              if (mainMetaTableUid === item.metauid) {
                // 属于主表的元素时
                formDataObj[item.model] = this.models[item.model]
              } else {
                if (mainMetaTableUid === item.main_refTableUid) {
                  let submetaUid = item.metauid
                  // 属于从表时(可编辑表格)
                  if (formDataObj['_subs']) {
                    // 获取从表的数据值---只需要获取从表显示的栏位对应的值
                    formDataObj['_subs'][submetaUid] = this.getSubmetaTableData(item.tableColumns, this.models[item.model])
                  } else {
                    formDataObj['_subs'] = {}
                    // 获取从表的数据值---只需要获取从表显示的栏位对应的值
                    formDataObj['_subs'][submetaUid] = this.getSubmetaTableData(item.tableColumns, this.models[item.model])
                  }
                }
              }
            }
          }
        })
      }
      return formDataObj
    },
    // 获取从表的数据值---只需要获取从表显示的栏位对应的值
    getSubmetaTableData (submetaTableColumns, submetaTableData) {
      let tableData = []
      if (submetaTableData.length) {
        // 对从表中的数据进行循环，剔除其中非显示的栏位的字段
        submetaTableData.forEach(item => {
          let dataObj = {}
          // 根据从表的栏位信息，通过indexName来判断从表中的数据是不是需要添加的
          for (let i = 0; i < submetaTableColumns.length; i++) {
            if (Object.keys(item).indexOf((submetaTableColumns[i].indexName)) !== -1) {
              if (submetaTableColumns[i].isShow) {
                // 只有显示的栏位对应的字段才会被添加
                dataObj[submetaTableColumns[i].indexName] = item[submetaTableColumns[i].indexName]
              }
            }
          }
          if (item['_default_pk']) {
            dataObj['_default_pk'] = item['_default_pk']
          } else {
            dataObj['_default_pk'] = ''
          }
          tableData.push(dataObj)
        })
      }
      return tableData
    },
    // 2.修改固有事件的请求参数
    changeInherentEventsRequestData (express) {
      let rowObj = (this.clickRow && !this.$isEmptyObject(this.clickRow)) ? JSON.parse(JSON.stringify(this.clickRow)) : null
      let pPageRowObj = (this.pPageRow && !this.$isEmptyObject(this.pPageRow)) ? JSON.parse(JSON.stringify(this.pPageRow)) : null
      let modelsObj = (this.models && !this.$isEmptyObject(this.models)) ? JSON.parse(JSON.stringify(this.models)) : null
      let fixedValue = {
        formKey: this.dynamicUid,
        limit: 10,
        page: 1
      }
      return commonUse_changeInherentEventParams(express, rowObj, modelsObj, fixedValue, pPageRowObj)
    },
    // 3.当事件执行时，还有下一个事件继续执行时，判断下一个事件------------判断下一个事件
    // eventType--非流程操作的事件类型，workflowEventItem.eventType流程事件的事件类型
    judgeNextEvent (eventType, eventItemNo, evalIndex, evalMetauid, workflowEventItem) {
      // 还有其它事件需要执行时
      if (workflowEventItem) {
        // 流程事件，执行顺序是根据 sortNum判断的， 0 代表的的是excute事件
        if (this.workflowBtnStatus[workflowEventItem.eventType][evalIndex].sortNum === 0) {
          this.executeWorkflow(evalIndex + 1, workflowEventItem)
        } else {
          if (this.workflowBtnStatus[workflowEventItem.eventType][evalIndex].workflowEventType === 'selfdefine') {
            // 自定义事件
            this.getEventsInfoByEventNo(this.workflowBtnStatus[workflowEventItem.eventType][evalIndex].eventsNo, eventType, evalIndex + 1, evalMetauid, workflowEventItem)
          } else if (this.workflowBtnStatus[workflowEventItem.eventType][evalIndex].workflowEventType === 'inherent') {
            // 固有事件
            // 根据流程事件的类型，判断该执行哪一个拓展事件
            if (this.currentClickType === 'Save_add' || this.currentClickType === 'Save_edit') {
              this.evalExtendEventOfSaveMethod(eventType, evalIndex + 1, evalMetauid, workflowEventItem)
            } else if (this.currentClickType === 'Submit') {
              this.evalExtendEventOfSubmitMethod(eventType, evalIndex + 1, evalMetauid, workflowEventItem)
            } else if (this.currentClickType === 'Pass' || this.currentClickType === 'Apply' || this.currentClickType === 'SubmitPending' || this.currentClickType === 'ActivePending') {
              this.evalExtendEventOfPassMethod(eventType, evalIndex + 1, evalMetauid, workflowEventItem)
            } else if (this.currentClickType === 'Reject' || this.currentClickType === 'SelectReject') {
              this.evalExtendEventOfRejectMethod(eventType, evalIndex + 1, evalMetauid, workflowEventItem)
            } else if (this.currentClickType === 'Delete') {
              this.evalTableDeleteRowMethod(eventType, evalIndex + 1, evalMetauid, workflowEventItem)
            } else if (this.currentClickType === 'Stop') {
              this.evalExtendEventOfStopMethod(eventType, evalIndex + 1, evalMetauid, workflowEventItem)
            }
          } else if (this.workflowBtnStatus[workflowEventItem.eventType][evalIndex].workflowEventType === 'updateNode') {
            // 更新当前节点
            this.evalWorkflowEventOfUpdateNode(this.workflowBtnStatus[workflowEventItem.eventType][evalIndex].nodeJson, eventType, evalIndex + 1, evalMetauid, workflowEventItem)
          } else if (this.workflowBtnStatus[workflowEventItem.eventType][evalIndex].workflowEventType === 'addNode') {
            // 创建下一个节点
            this.evalWorkflowEventOfAddNode(this.workflowBtnStatus[workflowEventItem.eventType][evalIndex].nodeJson, eventType, evalIndex + 1, evalMetauid, workflowEventItem)
          } else if (this.workflowBtnStatus[workflowEventItem.eventType][evalIndex].workflowEventType === 'deleteNode') {
            // 删除当前节点
            this.evalWorkflowEventOfDeleteNode(eventType, evalIndex + 1, evalMetauid, workflowEventItem)
          }
        }
      } else {
        // 非流程的操作时,事件的执行顺序是根据 actionIndex 决定的，0 代表的是固有事件
        // 当执行的是固有事件时
        if (this.currentEventsArray[evalIndex].actionIndex === 0) {
          // 删除表格行事件时
          if (eventType === 'deleteTable') {
            this.evalTableDeleteRowMethod(eventType, evalIndex + 1, evalMetauid, null)
          } else if (eventType === 'removeTable') {
            // 逻辑删除
            this.evalTableRemoveRowMethod(eventType, evalIndex + 1, evalMetauid, null)
          } else if (eventType === 'recoverTable') {
            // 恢复
            this.evalTableRecoverRowMethod(eventType, evalIndex + 1, evalMetauid, null)
          } else if (eventType === 'activeTable') {
            // 启用事件
            this.evalTableActiveRowMethod(eventType, evalIndex + 1, evalMetauid, null)
          } else if (eventType === 'deactiveTable') {
            // 停用事件
            this.evalTableDeactiveRowMethod(eventType, evalIndex + 1, evalMetauid, null)
          } else if (eventType === 'submitDialogForm_add' || eventType === 'submitForm_add') {
            // 提交新增事件时
            this.evalSubmitAddFormDataMethod(eventType, evalIndex + 1, evalMetauid, null)
          } else if (eventType === 'submitDialogForm_edit' || eventType === 'submitForm_edit') {
            // 提交编辑事件时
            this.evalSubmitEditFormDataMethod(eventType, evalIndex + 1, evalMetauid, null)
          } else if (eventType === 'extend_save') {
            // 保存事件时
            this.evalExtendEventOfSaveMethod(eventType, evalIndex + 1, evalMetauid, null)
          } else if (eventType === 'extend_submit') {
            // 提交事件时
            this.evalExtendEventOfSubmitMethod(eventType, evalIndex + 1, evalMetauid, null)
          } else if (eventType === 'extend_pass') {
            // 通过事件时
            this.evalExtendEventOfPassMethod(eventType, evalIndex + 1, evalMetauid, null)
          } else if (eventType === 'extend_reject') {
            // 驳回事件时
            this.evalExtendEventOfRejectMethod(eventType, evalIndex + 1, evalMetauid, null)
          } else if (eventType === 'extend_finish') {
            // 完成事件时
            this.evalExtendEventOfFinishMethod(eventType, evalIndex + 1, evalMetauid, null)
          } else if (eventType === 'extend_stop') {
            // 终止事件时
            this.evalExtendEventOfStopMethod(eventType, evalIndex + 1, evalMetauid, null)
          }
        } else {
          this.getEventsInfoByEventNo(this.currentEventsArray[evalIndex].eventsNo, eventType, evalIndex + 1, evalMetauid, null)
        }
      }
    },
    // -------------固有事件的执行----开始
    // 1.表格删除行事件
    evalTableDeleteRowMethod (eventType, evalIndex, evalMetauid, workflowEventItem) {
      if (this.clickRow && !this.$isEmptyObject(this.clickRow) && this.clickRow['_default_pk']) {
        this.$delete('/md_form/' + evalMetauid + '/' + this.clickRow['_default_pk']).then(data => {
          let dataInfo = data.data.result
          this.afterEval(dataInfo, eventType, '', evalIndex, evalMetauid, workflowEventItem)
        }).catch(error => {
          this.loading = false
          this.$message({
            message: error,
            type: 'error'
          })
        })
      } else {
        this.$message({
          message: '该操作没有获取到行信息（_default_pk），请检查',
          type: 'error'
        })
        this.loading = false
      }
    },
    // 1.1表格移除行事件
    evalTableRemoveRowMethod (eventType, evalIndex, evalMetauid) {
      if (this.clickRow && !this.$isEmptyObject(this.clickRow) && this.clickRow['_default_pk']) {
        this.$patch('/md_form/' + evalMetauid + '/' + this.clickRow['_default_pk'] + '/remove', {
          fixed_filter_express: this.changeInherentEventsRequestData(this.currentEventsArray[evalIndex - 1].fixed_filter_express),
          fixed_data_express: this.changeInherentEventsRequestData(this.currentEventsArray[evalIndex - 1].fixed_data_express)
        }).then(data => {
          let dataInfo = data.data.result
          this.afterEval(dataInfo, eventType, '', evalIndex, evalMetauid)
        }).catch(error => {
          this.loading = false
          this.$message({
            message: error,
            type: 'error'
          })
        })
      } else {
        this.$message({
          message: '该操作没有获取到行信息（_default_pk），请检查',
          type: 'error'
        })
        this.loading = false
      }
    },
    // 1.2表格恢复行事件
    evalTableRecoverRowMethod (eventType, evalIndex, evalMetauid) {
      if (this.clickRow && !this.$isEmptyObject(this.clickRow) && this.clickRow['_default_pk']) {
        this.$patch('/md_form/' + evalMetauid + '/' + this.clickRow['_default_pk'] + '/recover', {
          fixed_filter_express: this.changeInherentEventsRequestData(this.currentEventsArray[evalIndex - 1].fixed_filter_express),
          fixed_data_express: this.changeInherentEventsRequestData(this.currentEventsArray[evalIndex - 1].fixed_data_express)
        }).then(data => {
          let dataInfo = data.data.result
          this.afterEval(dataInfo, eventType, '', evalIndex, evalMetauid)
        }).catch(error => {
          this.loading = false
          this.$message({
            message: error,
            type: 'error'
          })
        })
      } else {
        this.$message({
          message: '该操作没有获取到行信息（_default_pk），请检查',
          type: 'error'
        })
        this.loading = false
      }
    },
    // 2.表格启用行事件
    evalTableActiveRowMethod (eventType, evalIndex, evalMetauid, workflowEventItem) {
      if (this.clickRow && !this.$isEmptyObject(this.clickRow) && this.clickRow['_default_pk']) {
        this.$patch('/md_form/' + evalMetauid + '/' + this.clickRow['_default_pk'] + '/active', {
          fixed_filter_express: this.changeInherentEventsRequestData(this.currentEventsArray[evalIndex - 1].fixed_filter_express),
          fixed_data_express: this.changeInherentEventsRequestData(this.currentEventsArray[evalIndex - 1].fixed_data_express)
        }).then(data => {
          let dataInfo = data.data.result
          this.afterEval(dataInfo, eventType, '', evalIndex, evalMetauid, workflowEventItem)
        }).catch(error => {
          this.loading = false
          this.$message({
            message: error,
            type: 'error'
          })
        })
      } else {
        this.$message({
          message: '该操作没有获取到行信息（_default_pk），请检查',
          type: 'error'
        })
        this.loading = false
      }
    },
    // 3.表格停用行事件
    evalTableDeactiveRowMethod (eventType, evalIndex, evalMetauid, workflowEventItem) {
      if (this.clickRow && !this.$isEmptyObject(this.clickRow) && this.clickRow['_default_pk']) {
        this.$patch('/md_form/' + evalMetauid + '/' + this.clickRow['_default_pk'] + '/deactive', {
          fixed_filter_express: this.changeInherentEventsRequestData(this.currentEventsArray[evalIndex - 1].fixed_filter_express),
          fixed_data_express: this.changeInherentEventsRequestData(this.currentEventsArray[evalIndex - 1].fixed_data_express)
        }).then(data => {
          let dataInfo = data.data.result
          this.afterEval(dataInfo, eventType, '', evalIndex, evalMetauid, workflowEventItem)
        }).catch(error => {
          this.loading = false
          this.$message({
            message: error,
            type: 'error'
          })
        })
      } else {
        this.$message({
          message: '该操作没有获取到行信息（_default_pk），请检查',
          type: 'error'
        })
        this.loading = false
      }
    },
    // 4.提交新增数据的方法
    evalSubmitAddFormDataMethod (eventType, evalIndex, evalMetauid, workflowEventItem) {
      this.$post('/md_form/' + evalMetauid, {
        data: this.getPostFormData(),
        fixed_data_express: this.changeInherentEventsRequestData(this.currentEventsArray[evalIndex - 1].fixed_data_express)
      }).then(data => {
        let dataInfo = data.data.result
        if (dataInfo.code === 'success') {
          if (dataInfo.data && !this.$isEmptyObject(dataInfo.data) && dataInfo.data._default_pk) {
            this.models['_default_pk'] = dataInfo.data._default_pk
          }
        }
        this.afterEval(dataInfo, eventType, '', evalIndex, evalMetauid, workflowEventItem)
      }).catch(error => {
        this.loading = false
        this.$message({
          message: error,
          type: 'error'
        })
      })
    },
    // 5.提交编辑数据的方法
    evalSubmitEditFormDataMethod (eventType, evalIndex, evalMetauid, workflowEventItem) {
      if (this.clickRow && !this.$isEmptyObject(this.clickRow) && this.clickRow['_default_pk']) {
        this.$patch('/md_form/' + evalMetauid + '/' + this.clickRow['_default_pk'], {
          data: this.getPostFormData(),
          fixed_data_express: this.changeInherentEventsRequestData(this.currentEventsArray[evalIndex - 1].fixed_data_express)
        }).then(data => {
          let dataInfo = data.data.result
          if (dataInfo.code === 'success') {
            if (dataInfo.data && !this.$isEmptyObject(dataInfo.data) && dataInfo.data._default_pk) {
              // this.$set(this.models, '_default_pk', dataInfo.data._default_pk)
              this.models['_default_pk'] = dataInfo.data._default_pk
            }
          }
          this.afterEval(dataInfo, eventType, '', evalIndex, evalMetauid, workflowEventItem)
        }).catch(error => {
          this.loading = false
          this.$message({
            message: error,
            type: 'error'
          })
        })
      } else {
        this.$message({
          message: '该操作没有获取到行信息（_default_pk），请检查',
          type: 'error'
        })
        this.loading = false
      }
    },
    // 6.拓展事件--保存
    evalExtendEventOfSaveMethod (eventType, evalIndex, evalMetauid, workflowEventItem) {
      let postData = this.getPostFormData()
      postData['_default_pk'] = ''
      if (this.clickRow && !this.$isEmptyObject(this.clickRow) && this.clickRow['_default_pk']) {
        postData['_default_pk'] = this.clickRow['_default_pk']
      }
      this.$post('/md_form/' + evalMetauid + '/save', {
        data: postData,
        fixed_filter_express: this.changeInherentEventsRequestData(this.currentEventsArray[evalIndex - 1].fixed_filter_express),
        fixed_data_express: this.changeInherentEventsRequestData(this.currentEventsArray[evalIndex - 1].fixed_data_express)
      }).then(data => {
        let dataInfo = data.data.result
        if (dataInfo.code === 'success') {
          if (dataInfo.data && !this.$isEmptyObject(dataInfo.data) && dataInfo.data._default_pk) {
            this.models['_default_pk'] = dataInfo.data._default_pk
            this.workFlowParams.primaryKey = dataInfo.data._default_pk // 获取保存事件的primaryKey
          }
        }
        this.afterEval(dataInfo, eventType, '', evalIndex, evalMetauid, workflowEventItem)
      }).catch(error => {
        this.loading = false
        this.$message({
          message: error,
          type: 'error'
        })
      })
    },
    // 7.拓展事件--提交
    evalExtendEventOfSubmitMethod (eventType, evalIndex, evalMetauid, workflowEventItem) {
      let postData = this.getPostFormData()
      postData['_default_pk'] = ''
      if (this.clickRow && !this.$isEmptyObject(this.clickRow) && this.clickRow['_default_pk']) {
        postData['_default_pk'] = this.clickRow['_default_pk']
      }
      this.$post('/md_form/' + evalMetauid + '/save', {
        data: postData
      }).then(data => {
        let dataInfo = data.data.result
        if (dataInfo.code === 'success') {
          this.models['_default_pk'] = dataInfo.data._default_pk
          this.workFlowParams.primaryKey = dataInfo.data._default_pk // 获取保存事件的primaryKey
          // 保存成功后再执行提交操作
          this.$patch('/md_form/' + evalMetauid + '/' + dataInfo.data._default_pk + '/submit', {
            fixed_filter_express: this.changeInherentEventsRequestData(this.currentEventsArray[evalIndex - 1].fixed_filter_express),
            fixed_data_express: this.changeInherentEventsRequestData(this.currentEventsArray[evalIndex - 1].fixed_data_express)
          }).then(data => {
            let dataInfo = data.data.result
            this.afterEval(dataInfo, eventType, '', evalIndex, evalMetauid, workflowEventItem)
          }).catch(error => {
            this.loading = false
            this.$message({
              message: error,
              type: 'error'
            })
          })
        } else {
          this.loading = false
          this.$message({
            message: dataInfo.msg,
            type: 'error'
          })
        }
      }).catch(error => {
        this.loading = false
        this.$message({
          message: error,
          type: 'error'
        })
      })
    },
    // 8.拓展事件--通过
    evalExtendEventOfPassMethod (eventType, evalIndex, evalMetauid, workflowEventItem) {
      if (this.clickRow && !this.$isEmptyObject(this.clickRow) && this.clickRow['_default_pk']) {
        this.$patch('/md_form/' + evalMetauid + '/' + this.clickRow['_default_pk'] + '/pass', {
          fixed_filter_express: this.changeInherentEventsRequestData(this.currentEventsArray[evalIndex - 1].fixed_filter_express),
          fixed_data_express: this.changeInherentEventsRequestData(this.currentEventsArray[evalIndex - 1].fixed_data_express)
        }).then(data => {
          let dataInfo = data.data.result
          this.afterEval(dataInfo, eventType, '', evalIndex, evalMetauid, workflowEventItem)
        }).catch(error => {
          this.loading = false
          this.$message({
            message: error,
            type: 'error'
          })
        })
      } else {
        this.$message({
          message: '该操作没有获取到行信息（_default_pk），请检查',
          type: 'warning'
        })
        this.loading = false
      }
    },
    // 9.拓展事件--驳回
    evalExtendEventOfRejectMethod (eventType, evalIndex, evalMetauid, workflowEventItem) {
      if (this.clickRow && !this.$isEmptyObject(this.clickRow) && this.clickRow['_default_pk']) {
        this.$patch('/md_form/' + evalMetauid + '/' + this.clickRow['_default_pk'] + '/reject', {
          fixed_filter_express: this.changeInherentEventsRequestData(this.currentEventsArray[evalIndex - 1].fixed_filter_express),
          fixed_data_express: this.changeInherentEventsRequestData(this.currentEventsArray[evalIndex - 1].fixed_data_express)
        }).then(data => {
          let dataInfo = data.data.result
          this.afterEval(dataInfo, eventType, '', evalIndex, evalMetauid, workflowEventItem)
        }).catch(error => {
          this.loading = false
          this.$message({
            message: error,
            type: 'error'
          })
        })
      } else {
        this.$message({
          message: '该操作没有获取到行信息（_default_pk），请检查',
          type: 'warning'
        })
        this.loading = false
      }
    },
    // 10.拓展事件--完成
    evalExtendEventOfFinishMethod (eventType, evalIndex, evalMetauid, workflowEventItem) {
      if (this.clickRow && !this.$isEmptyObject(this.clickRow) && this.clickRow['_default_pk']) {
        this.$patch('/md_form/' + evalMetauid + '/' + this.clickRow['_default_pk'] + '/finish', {
          fixed_filter_express: this.changeInherentEventsRequestData(this.currentEventsArray[evalIndex - 1].fixed_filter_express),
          fixed_data_express: this.changeInherentEventsRequestData(this.currentEventsArray[evalIndex - 1].fixed_data_express)
        }).then(data => {
          let dataInfo = data.data.result
          this.afterEval(dataInfo, eventType, '', evalIndex, evalMetauid, workflowEventItem)
        }).catch(error => {
          this.loading = false
          this.$message({
            message: error,
            type: 'error'
          })
        })
      } else {
        this.$message({
          message: '该操作没有获取到行信息（_default_pk），请检查',
          type: 'warning'
        })
        this.loading = false
      }
    },
    // 11.拓展事件--终止
    evalExtendEventOfStopMethod (eventType, evalIndex, evalMetauid, workflowEventItem) {
      if (this.clickRow && !this.$isEmptyObject(this.clickRow) && this.clickRow['_default_pk']) {
        this.$patch('/md_form/' + evalMetauid + '/' + this.clickRow['_default_pk'] + '/stop', {
          fixed_filter_express: this.changeInherentEventsRequestData(this.currentEventsArray[evalIndex - 1].fixed_filter_express),
          fixed_data_express: this.changeInherentEventsRequestData(this.currentEventsArray[evalIndex - 1].fixed_data_express)
        }).then(data => {
          let dataInfo = data.data.result
          this.afterEval(dataInfo, eventType, '', evalIndex, evalMetauid, workflowEventItem)
        }).catch(error => {
          this.loading = false
          this.$message({
            message: error,
            type: 'error'
          })
        })
      } else {
        this.$message({
          message: '该操作没有获取到行信息（_default_pk），请检查',
          type: 'warning'
        })
        this.loading = false
      }
    },
    // 12.流程类事件--更新当前节点
    evalWorkflowEventOfUpdateNode (nodeJson, eventType, evalIndex, evalMetauid, workflowEventItem) {
      if (nodeJson) {
        let submitData = JSON.parse(JSON.stringify(this.models))
        if (this.clickRow && !this.$isEmptyObject(this.clickRow)) {
          submitData = Object.assign(JSON.parse(JSON.stringify(this.clickRow)), submitData)
        }
        let nodeJsonObj = JSON.parse(nodeJson)
        let requestParams = {
          Title: this.getInputParamsMethods(nodeJsonObj.Title, submitData),
          Category: this.getInputParamsMethods(nodeJsonObj.Category, submitData),
          Status: this.getInputParamsMethods(nodeJsonObj.Status, submitData),
          Extend: this.getInputParamsMethods(nodeJsonObj.Extend, submitData),
          InstanceKey: this.workFlowParams.primaryKey,
          FormKey: this.dynamicUid,
          UserID: this.$store.state.userNo
        }
        this.$post('/WorkFlowTask/GenCurNodeWorkFlowTask', requestParams).then(data => {
          let dataInfo = data.data.result
          this.afterEval(dataInfo, eventType, '', evalIndex, evalMetauid, workflowEventItem)
        }).catch(error => {
          this.loading = false
          this.$message({
            message: error,
            type: 'error'
          })
        })
      } else {
        this.$message({
          message: '该事件没有设置参数，请前往元数据流程页面进行配置',
          type: 'warning'
        })
        this.loading = false
      }
    },
    // 13.流程类事件--新建下一个节点流程任务
    evalWorkflowEventOfAddNode (nodeJson, eventType, evalIndex, evalMetauid, workflowEventItem) {
      if (nodeJson) {
        let submitData = JSON.parse(JSON.stringify(this.models))
        if (this.clickRow && !this.$isEmptyObject(this.clickRow)) {
          submitData = Object.assign(JSON.parse(JSON.stringify(this.clickRow)), submitData)
        }
        let nodeJsonObj = JSON.parse(nodeJson)
        let requestParams = {
          Title: this.getInputParamsMethods(nodeJsonObj.Title, submitData),
          Category: this.getInputParamsMethods(nodeJsonObj.Category, submitData),
          Status: this.getInputParamsMethods(nodeJsonObj.Status, submitData),
          Extend: this.getInputParamsMethods(nodeJsonObj.Extend, submitData),
          NextTitle: this.getInputParamsMethods(nodeJsonObj.NextTitle, submitData),
          NextCategory: this.getInputParamsMethods(nodeJsonObj.NextCategory, submitData),
          NextStatus: this.getInputParamsMethods(nodeJsonObj.NextStatus, submitData),
          NextExtend: this.getInputParamsMethods(nodeJsonObj.NextExtend, submitData),
          IsCountersign: this.getInputParamsMethods(nodeJsonObj.IsCountersign, submitData),
          InstanceKey: this.workFlowParams.primaryKey,
          FormKey: this.dynamicUid,
          UserID: this.$store.state.userNo,
          ActionCode: (workflowEventItem.eventType === 'Save_add' || workflowEventItem.eventType === 'Save_edit') ? 'Save' : workflowEventItem.eventType
        }
        this.$post('/WorkFlowTask/GenNextNodeWorkFlowTask', requestParams).then(data => {
          let dataInfo = data.data.result
          this.afterEval(dataInfo, eventType, '', evalIndex, evalMetauid, workflowEventItem)
        }).catch(error => {
          this.loading = false
          this.$message({
            message: error,
            type: 'error'
          })
        })
      } else {
        this.$message({
          message: '该事件没有设置参数，请前往元数据流程页面进行配置',
          type: 'warning'
        })
        this.loading = false
      }
    },
    // 14.流程类事件--移除流程任务
    evalWorkflowEventOfDeleteNode (eventType, evalIndex, evalMetauid, workflowEventItem) {
      let submitData = JSON.parse(JSON.stringify(this.models))
      if (this.clickRow && !this.$isEmptyObject(this.clickRow)) {
        submitData = Object.assign(JSON.parse(JSON.stringify(this.clickRow)), submitData)
      }
      this.$post('/WorkFlowTask/RemoveWorkFlowTask', {
        TID: this.getInputParamsMethods('TID', submitData)
      }).then(data => {
        let dataInfo = data.data.result
        this.afterEval(dataInfo, eventType, '', evalIndex, evalMetauid, workflowEventItem)
      }).catch(error => {
        this.loading = false
        this.$message({
          message: error,
          type: 'error'
        })
      })
    },
    // -------------------------------------------------流程相关的事件
    // 获取流程表单的按钮显示状态和按钮事件
    getWorkflowBtnStatus (pageworkflowConfig) {
      if (pageworkflowConfig.hadWorkflow && pageworkflowConfig.workflowBtnEvents.length) {
        pageworkflowConfig.workflowBtnEvents.forEach(item => {
          let obj = {
            // 事件类别
            workflowEventType: item.workflowEventType,
            // 固有事件的表达式
            fixed_filter_express: item.filterExpress,
            fixed_data_express: item.dataExpress,
            // 节点事件的参数设置
            nodeJson: item.nodeJson,
            // 其它
            sortNum: item.actionIndex,
            eventsNo: item.eventsNo,
            eventType: item.btnType,
            btnName: item.btnName,
            inputDic: item.inputDic,
            outputDic: item.outputDic
          }
          this.workflowBtnStatus[item.btnType].push(obj)
        })
        // 删除和 保存不需要走流程, 其它事件需要在 0 位置增加一个走流程的固定事件
        for (let itemKey in this.workflowBtnStatus) {
          if (itemKey !== 'Delete' && itemKey !== 'Save_add' && itemKey !== 'Save_edit' && this.workflowBtnStatus[itemKey].length) {
            let obj = {
              // 事件类别
              workflowEventType: '',
              // 固有事件的表达式
              fixed_filter_express: '',
              fixed_data_express: '',
              // 节点事件的参数设置
              nodeJson: '',
              sortNum: 0,
              eventsNo: '',
              eventType: itemKey,
              btnName: this.workflowBtnStatus[itemKey][0].btnName,
              inputDic: [],
              outputDic: []
            }
            this.workflowBtnStatus[itemKey].push(obj)
          }
          this.workflowBtnStatus[itemKey].sort(this.orderByObjAttr('sortNum'))
        }
      } else {
        this.workflowBtnStatus = {
          Delete: [],
          Save_add: [],
          Save_edit: [],
          Submit: [],
          Pass: [],
          Reject: [],
          SelectReject: [],
          Stop: [],
          Apply: [],
          SubmitPending: [],
          ActivePending: []
        }
      }
    },
    // 点击流程相关的按钮时--判断需要执行的方法
    workflowMethod (type, btnName) {
      let msg = ''
      this.currentClickType = type
      if (type === 'Delete') {
        let info = btnName || '删除'
        msg = '确定要' + info + '该流程表单么?'
        this.$confirm(msg, '提示', {
          confirmButtonText: '确定',
          cancelButtonClass: 'el-button--info',
          cancelButtonText: '取消'
        }).then(() => {
          // 此时的删除的是已经保存过的数据
          if (this.workFlowParams.primaryKey) {
            this.loading = true
            this.currentEventsArray = JSON.parse(JSON.stringify(this.workflowBtnStatus[type]))
            this.judgeNextEvent(null, this.workflowBtnStatus[type][0].eventsNo, 0, this.pageFormInfo.pageConfig.refMainMetaTableUid, this.workflowBtnStatus[type][0])
            // if (this.workflowBtnStatus[type][0].sortNum === 0) {
            //   this.executeWorkflow(1, this.workflowBtnStatus[type][0])
            // } else {
            //   this.getEventsInfoByEventNo(this.workflowBtnStatus[type][0].eventsNo, null, 1, this.pageFormInfo.pageConfig.refMainMetaTableUid, this.workflowBtnStatus[type][0])
            // }
          } else {
            // 没有保存的删除，只需关闭弹窗
            this.$confirm(info + '成功', '提示', {
              showClose: false,
              showCancelButton: false,
              closeOnClickModal: false,
              closeOnPressEscape: false,
              confirmButtonText: '确定'
            }).then(() => {
              this.$refs['formMenuLayout'].resetValidate()
              this.$emit('closeDynamicMenuDialogSuccess')
            }).catch(() => {})
          }
        }).catch(() => {})
      } else {
        if (type === 'Save_add' || type === 'Save_edit') {
          let info = btnName || '保存'
          msg = '确定要' + info + '该流程表单么?'
        } else if (type === 'Submit') {
          let info = btnName || '提交'
          msg = '确定要' + info + '该流程表单么?'
        } else if (type === 'Pass') {
          let info = btnName || '通过'
          msg = '确定要' + info + '该流程表单么?'
        } else if (type === 'Apply') {
          let info = btnName || '申请'
          msg = '确定要' + info + '该流程表单么?'
        } else if (type === 'Reject' || type === 'SelectReject') {
          let info = btnName || '驳回'
          msg = '确定要' + info + '该流程表单么?'
        } else if (type === 'Stop') {
          let info = btnName || '终止'
          msg = '确定要' + info + '该流程表单么?'
        } else if (type === 'SubmitPending') {
          let info = btnName || '提交挂起'
          msg = '确定要' + info + '该流程表单么?'
        } else if (type === 'ActivePending') {
          let info = btnName || '恢复挂起'
          msg = '确定要' + info + '该流程表单么?'
        }
        if (this.$refs['formMenuLayout'].validateFormMethod()) {
          this.$confirm(msg, '提示', {
            confirmButtonText: '确定',
            cancelButtonClass: 'el-button--info',
            cancelButtonText: '取消'
          }).then(() => {
            if (type === 'SelectReject') {
              // 选择驳回时，需要选人
              this.showUserDialog = true
            } else if (type === 'ActivePending') {
              // 恢复挂起时，需要将获取到的人直接带入到NextUserList
              this.getPendingUserList()
            } else {
              this.loading = true
              this.currentEventsArray = JSON.parse(JSON.stringify(this.workflowBtnStatus[type]))
              this.judgeNextEvent(null, this.workflowBtnStatus[type][0].eventsNo, 0, this.pageFormInfo.pageConfig.refMainMetaTableUid, this.workflowBtnStatus[type][0])
              // if (this.workflowBtnStatus[type][0].sortNum === 0) {
              //   this.executeWorkflow(1, this.workflowBtnStatus[type][0])
              // } else {
              //   this.getEventsInfoByEventNo(this.workflowBtnStatus[type][0].eventsNo, null, 1, this.pageFormInfo.pageConfig.refMainMetaTableUid, this.workflowBtnStatus[type][0])
              // }
            }
          }).catch(() => {})
        }
      }
    },
    // 执行工作流的方法---当与工作相关的事件执行完成之后才执行该方法（工作流的按钮的执行顺序到 0 时）
    executeWorkflow (evalIndex, workflowEventItem) {
      let submitData = {}
      if (this.clickRow && !this.$isEmptyObject(this.clickRow)) {
        Object.assign(submitData, this.clickRow)
      }
      if (this.models && !this.$isEmptyObject(this.models)) {
        Object.assign(submitData, this.models)
      }
      if (!this.workFlowParams.primaryKey) {
        this.loading = false
        this.$message({
          message: '没有得到与流程相关的PrimaryKey',
          type: 'error'
        })
        return
      }
      this.$workflowPost('/WorkFlowEngine/Execute', {
        Data: {
          PrimaryKey: this.workFlowParams.primaryKey,
          FormKey: this.dynamicUid,
          NodeID: this.pageFormInfo.pageConfig.relatedWorkflowNode,
          UserID: this.$store.state.userNo,
          UserName: this.$store.state.userName,
          ActionCode: (workflowEventItem.eventType === 'Save_add' || workflowEventItem.eventType === 'Save_edit') ? 'Save' : workflowEventItem.eventType,
          ExtendData: (!this.$isEmptyObject(submitData) && submitData.Extend) ? submitData.Extend : '',
          Remark: (!this.$isEmptyObject(submitData) && submitData.$_Remark) ? submitData.$_Remark : '',
          NextUserList: this.NextUserList
        }
      }).then(data => {
        let dataResult = data.data.result
        if (dataResult.code === 'success') {
          // 获取返回的status值，已给后面的事件使用
          if (dataResult.data && dataResult.data.Status) {
            this.workFlowParams.status = dataResult.data.Status
          }
          // 是最后一个事件时
          if (this.workflowBtnStatus[workflowEventItem.eventType].length === evalIndex) {
            this.loading = false
            this.currentEventsArray = []
            let msg = (workflowEventItem.eventType === 'Save_add' || workflowEventItem.eventType === 'Save_edit') ? '保存成功' : (workflowEventItem.eventType === 'Delete' ? '删除成功' : '操作成功')
            this.$confirm(msg, '提示', {
              showClose: false,
              showCancelButton: false,
              closeOnClickModal: false,
              closeOnPressEscape: false,
              confirmButtonText: '确定'
            }).then(() => {
              // 保存时不需要刷新窗口
              // if (workflowEventItem.eventType !== 'Save_add' && workflowEventItem.eventType !== 'Save_edit') {
              //   if (this.dialogFormVisible) {
              //     this.$emit('closeDynamicMenuDialogSuccess')
              //   } else {
              //     this.init()
              //   }
              // }
              if (this.dialogFormVisible) {
                this.$emit('closeDynamicMenuDialogSuccess')
              } else {
                this.init()
              }
            }).catch(() => {})
          } else {
            // 还有其它的事件需要执行
            // 需要判断下一个事件是不是执行流程事件
            this.judgeNextEvent(null, this.workflowBtnStatus[workflowEventItem.eventType][evalIndex].eventsNo, evalIndex, this.pageFormInfo.pageConfig.refMainMetaTableUid, workflowEventItem)
          }
        } else if (dataResult.code === 'failed') {
          this.loading = false
          this.$message({
            message: dataResult.msg,
            type: 'error'
          })
        }
      }).catch(error => {
        this.loading = false
        this.$message({
          message: error,
          type: 'error'
        })
      })
    },
    // 特殊节点需要选人时---目前是actionCode为SelectReject的类型时
    // 放弃选人时---放弃驳回的操作
    giveUpChooseUser () {
      this.showUserDialog = false
    },
    // 确定选人时，需执行下一步的操作
    choosedUsersSuccess (fromChoosedUser) {
      this.showUserDialog = false
      this.NextUserList = fromChoosedUser
      // 选人成功后，执行驳回相关的操作
      this.loading = true
      this.currentEventsArray = JSON.parse(JSON.stringify(this.workflowBtnStatus[this.currentClickType]))
      this.judgeNextEvent(null, this.workflowBtnStatus[this.currentClickType][0].eventsNo, 1, this.pageFormInfo.pageConfig.refMainMetaTableUid, this.workflowBtnStatus[this.currentClickType][0])
    },
    // 恢复挂起时，需要获取NextUserList
    getPendingUserList () {
      this.loading = true
      let submitData = {}
      if (this.clickRow && !this.$isEmptyObject(this.clickRow)) {
        Object.assign(submitData, this.clickRow)
      }
      if (this.models && !this.$isEmptyObject(this.models)) {
        Object.assign(submitData, this.models)
      }
      this.$workflowPost('/WorkFlowEngine/ActivePendingUsers', {
        PrimaryKey: this.workFlowParams.primaryKey,
        NodeID: this.pageFormInfo.pageConfig.relatedWorkflowNode,
        UserID: this.$store.state.userNo,
        ExtendData: (!this.$isEmptyObject(submitData) && submitData.Extend) ? submitData.Extend : ''
      }).then(data => {
        let dataResult = data.data.result
        if (dataResult.code === 'success') {
          // 判断是否有人
          if (dataResult.data.length) {
            this.NextUserList = dataResult.data
            // 执行恢复挂起的相关操作
            this.currentEventsArray = JSON.parse(JSON.stringify(this.workflowBtnStatus[this.currentClickType]))
            this.judgeNextEvent(null, this.workflowBtnStatus[this.currentClickType][0].eventsNo, 1, this.pageFormInfo.pageConfig.refMainMetaTableUid, this.workflowBtnStatus[this.currentClickType][0])
          } else {
            this.loading = false
            // 当没有人时
            this.$message({
              message: '没有获取到恢复挂起的执行人员，请检查接口或流程是否有误',
              type: 'error'
            })
          }
        } else if (dataResult.code === 'failed') {
          this.loading = false
          this.$message({
            message: dataResult.msg,
            type: 'error'
          })
        }
      }).catch(error => {
        this.loading = false
        this.$message({
          message: error,
          type: 'error'
        })
      })
    }
  }
}
</script>
